package com.howie.hmvc.paramparse;

import java.lang.annotation.Annotation;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.howie.hmvc.annotations.Valid;
import com.howie.hmvc.exception.ArguErrorException;

public class ParamChart extends AbsParamParse{

	private boolean required;
	
	@Override
	public void init(Annotation[] an) throws Exception {
		Valid valid = getValid(an);
		if(valid != null){
			required = valid.required();
		}
	}
	
	@Override
	public Object getParamter(HttpServletRequest request,HttpServletResponse response)throws Exception{
		String value = request.getParameter(name);
		if(value == null || value.length() == 0){
			if(required){
				throw new ArguErrorException(name,"required",null);
			}
		}else{
			return value.charAt(0);
		}
		return null;
	}
	
}
